<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title><{:C('web_site_name')}>---广告类型管理</title>
    <link rel="stylesheet" type="text/css" href="<?php echo APP_TMPL_PATH ; ?>/static/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="<?php echo APP_TMPL_PATH ; ?>/static/css/main.css"/>

    <script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/jquery.js"></script>
    <script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/layer/lib.js"></script>
<script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/layer/layer.min.js"></script>
<script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/admin.js"></script>
</head>
<body>
<div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i>首页<span class="crumb-step">&gt;</span><span class="crumb-name">后台广告类型管理</span></div>
        </div>
        <div class="search-wrap">
            <div class="search-content">
                <form action="#" method="post">
                    <table class="search-tab">
                        <tr>
                          
                            <th width="70">广告位置:</th>
                            <td><input class="common-text" placeholder="广告位置" name="typename" value="" id="typename" type="text"></td>
                            
                     
                                <th width="70">状态:</th>
                                <td>
                             <select name="status">
                                <option value="all">请选择</option>
                                <option value="1">开启</option>
                                <option value="0">关闭</option>  
                            </select>
                                </td>
                            <td>
                            <input class="btn btn-primary btn2" name="sub" value="查询" type="button" onclick="search()">
                           &nbsp;&nbsp;&nbsp;
                            
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
                <div class="result-title">
                    <div class="result-list">
                        <a href="javascript:void(0)" onclick="add()"><i class="icon-font"></i>新增广告类型</a>
                        <input class="btn btn-primary btn2" name="sub" value="一键更新缓存" type="button" onclick="update_ad(1)">
                    </div>
                </div>
                 <div class="list-page" id="page_string"> 2 条 1/1 页</div>
                <div class="result-content">
                    <table class="result-tab" width="100%" >
                        <tr>
                            <th>编号</th>
                            <th>广告位置</th>
                            <th>描述</th>
                            <th>缩略图</th>
                          
                            <th>添加日期 </th>
                            <th>修改日期 </th>
                     
                            <th>状态</th>
                        
                       
                            <th>操作</th>
                        </tr>
                      <tbody id="result_"></tbody>
                        
                    </table>
                    <tbody id="result_all">
                      	<tr>
                      		<td colspan="14">
                      		<input type="checkbox"  id="selAll" onclick="selectAll()">
                      		<input class="btn btn-primary btn2" name="sub" value="更新广告缓存" type="button" onclick="update_ad(0)">
                      		</td>
                      	</tr>
                      </tbody>
                        
                    <div class="list-page" id="page_string"> 2 条 1/1 页</div>
                </div>
            </form>
        </div>
</body>
</html>
<script>
var loadding_0  ;
var page = 1 ;
$(function () {
    common_request();
});
function common_request(){
    var url="<?php echo U("adtype/index");?>&inajax=1";
    var data_ = {
        'page':page,
        'time':<?php echo time();?>,
        'action':'ajax_data' , 
        'typename':$("input[name='typename']").val() , 
        'status':$("select[name='status']").val()

    } ;
    $.ax(
        url,data_,true,"POST","JSON",function(msg){
var shtml = '' ;
        var list = msg.resultinfo.list;
        
        if(msg.resultcode!= 1 ){
            layer.msg(msg.resultinfo.errmsg);
            return false ;
        }else{
        
            for(var i in list){
                shtml+='<tr>';
                shtml+= '<td><input type="checkbox" name="checkAll[]" value="'+list[i].id+'">'+list[i].id+'</td>' ;
                shtml+='<td>'+list[i]['typename']+'</td>';
                shtml+='<td>'+list[i]['info']+'</td>';
                shtml+='<td>'+list[i]['pic']+'</td>';
               
                shtml+='<td>'+list[i]['addtime']+'</td>';
                shtml+='<td>'+list[i]['updatetime']+'</td>';
             
                shtml+='<td>'+list[i]['status']+'</td>';
           
                shtml+='<td><a href="javascript:void(0)" onclick="useAd('+list[i].id+')" class="tablelink">调用</a>&nbsp;&nbsp; <a href="javascript:void(0)" onclick="edit('+list[i].id+',this)" class="tablelink">修改</a>&nbsp;&nbsp;</td>';
                shtml+='</tr>';
            }
            $("#result_").html(shtml);
            $(".list-page").html(msg.resultinfo.obj);
        }
        layer.close(loadding_0);        
        },function(e){
            layer.msg('服务器繁忙请稍后');
            return false ;   
        },function(f){
            loadding_0 = layer.load('数据正在加载中1。。。。。。'); 
        }
    );    
  
}
function ajax_data(p){
    page = p  ; 
    common_request();
}
function search(){
    page = 1 ;
    common_request();
}
var _add = '' ;
//添加广告类型
function add(){
    _add = $.layer({
        type: 2,
        shadeClose: true,
        title: "添加广告类型",
        closeBtn: [0, true],
        shade: [0.8, '#000'],
        border: [1],
        offset: ['20px',''],
        area: ['60%','60%'],
        iframe: {src: "<?php echo U("adtype/add");?>&showpage=1"}
    }); 
}
var _edit = '' ;

function edit(id , o ){
    _edit = $.layer({
        type: 2,
        shadeClose: true,
        title: "修改广告类型",
        closeBtn: [0, true],
        shade: [0.8, '#000'],
        border: [1],
        offset: ['20px',''],
        area: ['60%','60%'],
        iframe: {src: "<?php echo U("adtype/edit");?>&showpage=1&id="+id}
    }); 
}
//关闭窗口
function close_add_div(){
    layer.close(_add);
}
//关闭窗口
function close_edit_div(){
    layer.close(_edit);
}
//编辑状态
function editStatus (id , status ){
    $.ajax({
    type: "POST",
    url: "<{:U('adtype/edit')}>&action=doStatus" ,
    data: {id:id , status:status},
    cache:false,
    dataType:"json",
    async:true,
    success: function(msg){
        var shtml = '' ;
        var list = msg.resultinfo.list;
        
        if(msg.resultcode!= 1 ){
            layer.msg(msg.resultinfo.errmsg);
            return false ;
        }else{
            
        }
        layer.close(loadding_0);
    },
    beforeSend:function(){
         loadding_0 = layer.load('数据正在处理中。。。。。。'); 
    },
    error:function(){
        layer.msg('服务器繁忙请稍后');
        return false ;
    }
    });
}
//调用广告
function useAd(id){
    var pageii = $.layer({
        type: 1,
        title: false,
        shadeClose: true,
        area: ['auto', 'auto'],
        border: [0], //去掉默认边框
        shade: [0.8, '#000'],
        closeBtn: [1, true], //去掉默认关闭按钮
        shift: 'right', //从左动画弹出
        page: {
            html: '<div style="width:420px; height:120px; padding:20px; border:1px solid #ccc; background-color:#eee;"><p>广告调用方式:<font color="red">query_ad_by_typeid('+id+')</font> ;<br/> </p><p>1：第一个参数是 广告位置ID</p><p>2：返回值是数组的形式！请根据自己的业务需求进行遍历数组</p></div>'
        }
    });
}
function update_ad(t){
	var id = ''  ;
	if(t == 0 ){
		var obj=document.getElementsByName("checkAll[]");
	 	var count = obj.length;
	 	var selectCount = 0;
	 	for(var i = 0; i < count; i++)
	 	{
	 		if(obj[i].checked == true)
	 		{
	 			id = id +obj[i].value+',';
	 			selectCount++;
	 		}
	 		
	 	}
	 	if(selectCount <= 0 ){
	 		layer.msg("请选择广告类型进行更新缓存");
	 		return false ;
	 	}
	 	id = id.substring(0 , id.length - 1 );
	}
    $.ajax({
        type: "POST",
        url: "<{:U('adtype/update_ad_cache')}>&action=1" ,
        data: {id:id , type:t},
        cache:false,
        dataType:"json",
        async:true,
        success: function(msg){
            var shtml = '' ;
            var list = msg.resultinfo.list;
            
            if(msg.resultcode!= 1 ){
                layer.msg(msg.resultinfo.errmsg);
                return false ;
            }else{
            	$.layer({dialog: {type: 10,msg: msg.resultinfo.errmsg}});
            }
            layer.close(loadding_0);
        },
        beforeSend:function(){
             loadding_0 = layer.load('数据正在处理中。。。。。。'); 
        },
        error:function(){
            layer.msg('服务器繁忙请稍后');
            return false ;
        }
        });	
}
</script> 

